#!/bin/bash

README="$PWD/benchmarks/README.md"

# Clear README
> $README

echo "
### Securibench Micro

Securibench Micro is a series of small test cases designed to exercise different parts of a static security analyzer.
Securibench Micro may be used to compare the effectiveness of runtime techniques such as penetration testing tools.

* Java source: \`sbt \"benchmarks / testOnly *.securibench.micro.java.*\"\`
* JVM bytecode: \`sbt \"benchmarks / testOnly *.securibench.micro.jvm.*\"\`
" >> $README

echo "#### Java Source Results" >> $README

export JOERN_BENCHMARK_RESULT_FILE="$PWD/securibench_micro_java.txt"
sbt "benchmarks / testOnly *.securibench.micro.java.*"
cat $JOERN_BENCHMARK_RESULT_FILE >> $README

echo "#### JVM Bytecode Results" >> $README

export JOERN_BENCHMARK_RESULT_FILE="$PWD/securibench_micro_jvm.txt"
sbt "benchmarks / testOnly *.securibench.micro.jvm.*"
cat $JOERN_BENCHMARK_RESULT_FILE >> $README

echo "
### IFSpec

IFSpec contains a diverse set of information flow benchmarks for Java programs.

* Java source: \`sbt \"benchmarks / testOnly *.ifspec.java.*\"\`
* JVM bytecode: \`sbt \"benchmarks / testOnly *.ifspec.jvm.*\"\`
" >> $README

echo "#### Java Source Results" >> $README

export JOERN_BENCHMARK_RESULT_FILE="$PWD/ifspec_java.txt"
sbt "benchmarks / testOnly *.ifspec.java.*"
cat $JOERN_BENCHMARK_RESULT_FILE >> $README

echo "#### JVM Bytecode Results" >> $README

export JOERN_BENCHMARK_RESULT_FILE="$PWD/ifspec_jvm.txt"
sbt "benchmarks / testOnly *.ifspec.jvm.*"
cat $JOERN_BENCHMARK_RESULT_FILE >> $README

echo "
### JInfoFlow

JInfoFlow-bench is a taint analysis benchmark suite containing 12 plain Java benchmarks exercising reflection,
event-driven architecture, and popular software engineering patterns.

* Java source: \`sbt \"benchmarks / testOnly *.jinfoflow.java.*\"\`
* JVM bytecode: \`sbt \"benchmarks / testOnly *.jinfoflow.jvm.*\"\`
" >> $README

echo "#### Java Source Results" >> $README

export JOERN_BENCHMARK_RESULT_FILE="$PWD/jinfoflow_java.txt"
sbt "benchmarks / testOnly *.jinfoflow.java.*"
cat $JOERN_BENCHMARK_RESULT_FILE >> $README

echo "#### JVM Bytecode Results" >> $README

export JOERN_BENCHMARK_RESULT_FILE="$PWD/jinfoflow_jvm.txt"
sbt "benchmarks / testOnly *.jinfoflow.jvm.*"
cat $JOERN_BENCHMARK_RESULT_FILE >> $README

# Clean up
rm *.txt